﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace GregTech_Resource
{
    public partial class Form1 : Form
    {
        int TotalRes, CurrRes;
        byte page = 1;
        ArrayList SearchResult;

        Form2 AboutForm;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            Ore.LoadOre();
            Lode.LoadLode();
            AboutForm = new Form2();
            AboutForm.Hide();
        }

        private void Search_Click(object sender, EventArgs e)
        {
            if(page == 1)
                SearchResult = new ArrayList(Lode.SearchLode(textBox1.Text));
            else if (page == 2)
                SearchResult = new ArrayList(Ore.SearchOre(textBox1.Text));

            if (SearchResult.Count == 0)
            {
                label2.Text = "对不起，未找到您搜索的矿物！";
                label1.Text = "0 / 0";
            }
            else
            {
                TotalRes = SearchResult.Count;
                SwitchTo(0);
            }
        }

        private void SwitchTo(int n)
        {
            if(page == 1)
            {
                Lode l = SearchResult[n] as Lode;
                label2.Text = l.OutputLode();
            }
            else if(page == 2)
            {
                Ore o = SearchResult[n] as Ore;
                label2.Text = o.OutputOre();
            }
            
            CurrRes = n;
            label1.Text = (CurrRes + 1).ToString() + " / " + TotalRes.ToString();

            if (CurrRes == 0)
                button1.Enabled = false;
            else
                button1.Enabled = true;
            if (CurrRes == TotalRes - 1)
                button2.Enabled = false;
            else
                button2.Enabled = true;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            SwitchTo(CurrRes - 1);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            SwitchTo(CurrRes + 1);
        }

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            if (page == 1)
                page = 2;
            else if (page == 2)
                page = 1;
            textBox1.Text = "";
            label2.Text = "请输入搜索内容~";
            label1.Text = "0 / 0";
            button1.Enabled = false;
            button2.Enabled = false;
        }

        private void label3_Click(object sender, EventArgs e)
        {
            AboutForm.Show();
        }
    }
}
